<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>冒泡排序</title>
</head>
<body>
   <script>
       
      
       /*
         var daa =[50,46,87,98,15,144];
         var sum = 0 ;
         for(var i = 0 ; i<daa.length;i++){
         sum += daa[i];
         }
         alert(sum/daa.length);*/

        /*var tcc = ["小王吧",26,"男",123];
        alert("我叫"+tcc[0] +" 性别"+tcc[2]+"今年"+tcc[2]+"岁啦！"+"体重"+tcc[3]+"斤");
        */



        /*var add =[8,4,2,1,23,344,12];
        var sum = 0;
        for (var i = 0 ; i < add.length; i++){
            sum += add[i];
            console.log(add[i]);
        } 
       console.log(sum);
       */
    
        
       
       
       /*var add = [12,45,877,156,1454,0.1];
       var daa = add[0];
       for(var i = 1;i< add.length;i++){
           if(add[i] > daa){
               daa = add[i];
            }
       }
       console.log (daa);
    */
       
       
       
       /*var tcc = ["小王吧",26,"男",123];
       //tcc.pop();
       tcc.push("gongjin");
       alert(tcc);
       */
       
       
       
       
       
       
       /*
       function sortNumber(a,b){
            return a - b;
       }
       var add = [10,5,87,15,0,14,67,2,4,6];
       console.log(add + "<br />");
       console.log(add.sort(sortNumber) + "<br />");*/
       
       
       
        
//冒泡排序      
       /*
       function s(add){
           for (var i= 0 ; i < add.length;i++){
               for(var j= 0;j < add.length - i;j++){
                   if(add[j] > add[j+1]){
                       var seap = add[j];
                       add[j] = add[j + 1];
                       add[j + 1] = seap;
                   }
               }
           }
       }
       var add = [10,5,87,15,0,14,67,2,4,6];
       console.log('before:' + add);
       s(add);
       console.log('after:'+ add);*/

       
       
       
       /* 
       var arr = [1,2,85,698,45,14,35,48,123,14];
       for(var i = 0 ;i<arr.length - 1; i++){
        for(var j = 0 ; j< arr.length - i - 1;j++){
            if(arr[j] > arr[j+1]){
                var sum = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = sum;
            }
        }
           
       }
       console.log(arr);*/
       
       
       var arr = [1,5,7,45,3];
        console.log(arr);
       for(var k = 0;k < arr.length - 1;k++){
           for (var i= 0 ;i < arr.length - k - 1 ;i++){
               if(arr[i] > arr[i+1]){
                   var temp = arr[i];
                   arr[i] = arr[i+1];
                   arr[i+1] = temp;
               }
           }
       }
       console.log(arr);
       
       /*if(arr[1] > arr[1+1]){
           var p = arr[1];
           arr[1] = arr[1+1];
           arr[1+1] = temp;
       }
       if(arr[2] > arr[2+1]){
           var temp = arr[2];
           arr[2] = arr[2+1];
           arr[2+1] = temp;
       }
       if(arr[3] > arr[3+1]){
           var temp = arr[3];
           arr[3] = arr[3+1];
           arr[3+1] = temp;
       }
       if(arr[4] > arr[4+1]){
           var temp = arr[4];
           arr[4] = arr[4+1];
           arr[4+1] = temp;
       }*/
       
     
       
       
       
       
//金字塔       
       /*var num = 5;
        for (var i = 0; i < num; i++){
            for (var j = 0; j < num - i - 1; j++){
                document.write("&nbsp");
            }
            for (var p = 0; p <= 2 * i; p++){
                document.write("*");
            }
            document.write("<br>");
        }*/
       
       
       
       /*for(var i = 0;i < num ;i++) {
            for (var k = 0; k < num - i - 1; k++) {
                document.writeln("&nbsp;");
            }
            for (var j = 0; j <= (2 * i -1) + 1; j++) {
                document.writeln("*");
            }
            document.writeln("<br/>");
        }*/
       
       
       
       /*var sum = 6;
       for(var i = 0 ;i < sum ;i++){
           for (var k = 0 ; k< sum - i;k++){
               document.write("&nbsp;");
           }
           for (var j = 0 ; j<= 2 * i;j++){
               document.write("*");
           }
           document.write("<br>");
       }*/

    </script>
</body>
</html>